﻿using System;
using System.Linq;
using PTop.Code;
using PTop.Domain.Entity.Biz;
using PTop.Domain.IRepository.Biz;
using PTop.Repository.Biz;
using System.Collections.Generic;

namespace PTop.Application.Biz
{
    /// <summary>
    /// 附件信息App
    /// </summary>	
    public class AttachmentApp
    {
        private IAttachmentRepository service = new AttachmentRepository();

        public List<AttachmentEntity> GetList(Pagination pagination, string keyword)
        {
            var expression = ExtLinq.True<AttachmentEntity>();
            if (!string.IsNullOrEmpty(keyword))
            {
                //expression = expression.And(t => t.F_OrgnaizeName.Contains(keyword));
                //expression = expression.Or(t => t.F_CreatorUserCode.Contains(keyword));
            }
            return service.FindList(expression, pagination);
        }

        public AttachmentEntity GetForm(string keyValue)
        {
            return service.FindEntity(keyValue);
        }

        public void Delete(string keyValue)
        {
            service.Delete(t => t.F_Id == keyValue);
        }

        public void SubmitForm(AttachmentEntity entity, string keyValue)
        {
            if (!string.IsNullOrEmpty(keyValue))
            {
                service.Update(entity);
            }
            else
            {
                entity.Create();
                //entity.F_LastModifyTime = entity.F_CreatorTime;
                //entity.F_LastModifyUserId = entity.F_CreatorUserId;
                service.Insert(entity);
            }
        }

        public void Save(AttachmentEntity entity)
        {
            entity.Create();
            service.Insert(entity);
        }
        /// <summary>
        /// 今日已传图片数
        /// </summary>
        /// <param name="openId"></param>
        /// <returns></returns>
        public int CountToday(string openId)
        {
            var begin = DateTime.Now.Date;
            return service.Count(m => m.F_CreatorUserId == openId && m.F_CreatorTime.Value > begin);
        }
    }
}